<template>
	<div>
		<script id="editor" type="text/plain"></script>
	</div>
</template>

<script>
	import '../../../../static/third/editor/ueditor.config.js';
	import '../../../../static/third/editor/ueditor.all.min.js';
	import '../../../../static/third/editor/lang/zh-cn/zh-cn.js';
	import '../../../../static/third/editor/ueditor.parse.min.js';
	import '../../../../static/third/editor/dialogs/xiumi/xiumi-ue-dialog-v5.js';
	import '../../../../static/third/editor/dialogs/xiumi/xiumi-ue-v5.css';
	import Util from '../../../common/util.js';
	export default {
		name: 'editor',
		data() {
			return {
				editor: null,
				isReady: false
			}
		},
		props: {
			defaultMsg: {
				type: String
			},
			config: {
				type: Object
			}
		},
		watch: {
			defaultMsg(val) {
				this.initContext();
			}
		},
		mounted() {
			const _this = this;
			this.editor = UE.getEditor('editor', this.config); // 初始化UE
			this.editor.addListener("ready", function() {
				_this.isReady = true;
				_this.initContext();
			});
		},
		methods: {
			initContext() {
				if(this.isReady) {
					if(!Util.vad.isBlank(this.defaultMsg)) {
						this.editor.setContent(this.defaultMsg);
					}
				}
			},
			getUEContent() {
				return this.editor.getContent();
			},
			setUEContent(content) {
				if(this.isReady) {
					this.editor.setContent(content);
				}
			}
		},
		destroyed() {
			if(this.isReady) {
				this.editor.destroy();
			}
		}
	}
</script>

<style scoped>

</style>